﻿using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using AesonBaseFramework.EntityFramework.DbContexts;

namespace AesonBaseFramework.EntityFramework.Helpers
{
    public static  class ConnectionStringFactory
    {
        #region Build ConnectionString

       public static string GetConnectionString(DbConnectionInfo info)
       {
           if (info.DbSecurityType == DbSecurityType.Integrated)
           {
               var sqlBuilder = new SqlConnectionStringBuilder
               {
                   DataSource = info.Server,
                   InitialCatalog = info.Database,
                   PersistSecurityInfo = true,
                   IntegratedSecurity = true,
                   MultipleActiveResultSets = true
               };

               return sqlBuilder.ToString(); 
           }
           else
           {
               var sqlBuilder = new SqlConnectionStringBuilder
               {
                   DataSource = info.Server,
                   InitialCatalog = info.Database,
                   PersistSecurityInfo = true,
                   IntegratedSecurity = false,
                   UserID = info.DbLogin,
                   Password = info.DbPassword,
                   MultipleActiveResultSets = true
               };

               return sqlBuilder.ToString();
           }
         
       }
    
       public static string GetConnectionString(string server, string database)
        {

            var sqlBuilder = new SqlConnectionStringBuilder
            {
                DataSource = server,
                InitialCatalog = database,
                PersistSecurityInfo = true,
                IntegratedSecurity = true,
                MultipleActiveResultSets = true
            };

            return sqlBuilder.ToString();
        }

       public static string GetConnectionString(string server, string database, string dbLogin, string dbPasword)
        {

            var sqlBuilder = new SqlConnectionStringBuilder
            {
                DataSource = server,
                InitialCatalog = database,
                PersistSecurityInfo = true,
                IntegratedSecurity = false,
                UserID = dbLogin,
                Password = dbPasword,
                MultipleActiveResultSets = true
            };

            return sqlBuilder.ToString();
        }
        #endregion
    }
}
